{template 'common/header'}
<div class="main">
	<ul class="nav nav-tabs">
		<li{if $_GPC['do'] == 'manage'} class="active"{/if}><a href="{php echo $this->createWebUrl('manage');}">抢红包管理</a></li>
		<li{if $_GPC['do'] == 'post'} class="active"{/if}><a href="{php echo url('platform/reply/post',array('m'=>'stonefish_redenvelope'));}">添加抢红包规则</a></li>
		<li{if $_GPC['do'] == 'fanslist'} class="active"{/if}><a href="{php echo $this->createWebUrl('fanslist',array('rid' => $rid));}">参与粉丝</a></li>
		{if $reply['envelope']==0}<li{if $_GPC['do'] == 'awardlist'} class="active"{/if}><a href="{php echo $this->createWebUrl('awardlist',array('rid' => $rid));}">兑换记录</a></li>{/if}
		{if $reply['envelope']==1}<li{if $_GPC['do'] == 'tixianlist'} class="active"{/if}><a href="{php echo $this->createWebUrl('tixianlist',array('rid' => $rid));}">提现记录</a></li>{/if}
		{if $stonefish_branch}<li{if $_GPC['do'] == 'branch'} class="active"{/if}><a href="{php echo $this->createWebUrl('branch',array('rid' => $rid));}">商家赠送项</a></li>{/if}
		<li><a href="{php echo url('platform/reply/post',array('m'=>'stonefish_redenvelope', 'rid' => $rid));}">编辑抢红包规则</a></li>
	</ul>
    <div class="panel panel-info">
	<div class="panel-heading">筛选</div>
	<div class="panel-body">
		<form action="./index.php" method="get" class="form-horizontal" role="form">
			<input type="hidden" name="c" value="site" />
			<input type="hidden" name="a" value="entry" />
        	<input type="hidden" name="m" value="stonefish_redenvelope" />
        	<input type="hidden" name="do" value="awardlist" />
        	<input type="hidden" name="rid" value="{$_GPC['rid']}" />
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">关键字</label>
				<div class="col-xs-12 col-sm-8 col-lg-9">
					<input class="form-control" name="keywords" id="" type="text" value="{$_GPC['keywords']}" placeholder="可查询SN码,手机号"> 
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">奖品类别</label>
				<div class="col-xs-12 col-sm-8 col-lg-9">
					<select name="award" class="form-control" style="float:left">
                    	<option value="" {if $_GPC['status']==''}selected{/if}>全部</option>
						{loop $award $awards}
						<option value="{$awards['prizetype']}" {if $_GPC['award']==$awards['prizetype']}selected{/if}>{$awards['prizetype']}</option>						
						{/loop}
                	</select> 
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
				<div class="col-xs-12 col-sm-8 col-lg-9">
					<select name="status" class="form-control" style="float:left">
                    	<option value="" {if $_GPC['status']==''}selected{/if}>全部</option>
						<option value="1" {if $_GPC['status']=='1'}selected{/if}>未兑换</option>
                        <option value="2" {if $_GPC['status']=='2'}selected{/if}>已兑换</option>
                	</select>
				</div>
                <div class=" col-xs-12 col-sm-2 col-lg-2">
					<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
	<div class="row-fluid">
    	<div class="span8 control-group">
			<a class="btn btn-default{if $_GPC['status']==''} btn-primary active{/if}" href="{php echo $this->createWebUrl('awardlist',array('rid'=>$rid,'award'=>$_GPC['award']))}">全　部</a>
			<a class="btn btn-default{if $_GPC['status']=='1'} btn-primary active{/if}" href="{php echo $this->createWebUrl('awardlist',array('rid'=>$rid,'status'=>1,'award'=>$_GPC['award']))}">未兑换</a>
			<a class="btn btn-default{if $_GPC['status']=='2'} btn-primary active{/if}" href="{php echo $this->createWebUrl('awardlist',array('rid'=>$rid,'status'=>2,'award'=>$_GPC['award']))}">已兑换</a>			
        </div>
    </div>
	<div class="alert" style="margin-bottom:0;">本次活动奖品总数：{$num1}个　　抽中未兑换：{$num2}个　　抽中已兑换：{$num3}个</div>
	<div class="row-fluid">
    	<div class="span8 control-group">
			<a class="btn btn-default{if $_GPC['award']==''} btn-primary active{/if}" href="{php echo $this->createWebUrl('awardlist',array('rid'=>$rid,'status'=>$_GPC['status']))}">全　部</a>
			{loop $award $awardp}
			<a class="btn btn-default{if $_GPC['award']==$awardp['prizetype']} btn-primary active{/if}" href="{php echo $this->createWebUrl('awardlist',array('rid'=>$rid,'status'=>$_GPC['status'],'award'=>$awardp['prizetype']))}">{$awardp['prizetype']}</a>
			{/loop}			
        </div>
    </div>
	<div class="alert" style="margin-bottom:0;">
		{loop $award $awardt}
		    {$awardt['prizetype']}:{$awardt['prizedraw']}个/{$awardt['prizetotal']}个　　
		{/loop}			
	</div>
	<div class="row-fluid">
    	<div class="span8 control-group">			
			<a class="btn btn-primary" href="{php echo $this->createWebUrl('download',array('rid'=>$rid,'status'=>$_GPC['status'],'award'=>$_GPC['award']))}"><i class="fa fa-download"></i> 导出{$statustitle}兑奖信息</a>
        </div>
    </div>
</div>
	<form method="post" class="form-horizontal" id="form1">
	<input type="hidden" name="op" value="del" />
	<div style="position:relative">
		<div class="panel-body table-responsive">
			<table class="table table-hover" style="position:relative">
			<thead class="navbar-inner">
				<tr>
					<th style="width:50px;">删？</th>
					<th style="width:80px;">奖品类别</th>
					<th style="width:90px;">状态</th>
					<th width="120px">领取者姓名</th>
					<th style="width:120px;">领取者手机号</th>
					<th style="width:120px;">中奖时间</th>
					<th style="width:120px;">使用时间</th>
					<th style="width:100px;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $row}
				<tr>
					<td><input type="checkbox" name="uid[]" value="{$row['id']}" class=""></td>
					<td>{$row['name']}</td>
					<td>{if $row['status']==0}<span class="label label-danger">被取消
						{elseif $row['status']==1}<span class="label label-warning">未兑奖
						{else}<span class="label label-success">已兑奖{/if}
						{if $row['xuni']==0}/真实</span>
						{else}/虚拟</span>{/if}</td>
					<td><a href="javascript:void(0)" fid="{$row['fid']}" class="btn btn-default btn-sm userinfo" style="width:100px;" data-toggle="tooltip" data-placement="top" title="用户兑奖参数项"><i class="fa fa-child"></i> {$row['realname']}</a></td>
					<td>{$row['mobile']}</td>
					<td>{php echo date('Y/m/d H:i',$row['createtime']);}</td>
					<td>{if $row['consumetime'] == 0}未使用{else}{php echo date('Y/m/d H:i',$row['consumetime']);}{/if}</td>
					<td>
						{if $row['status']==1}<a class="btn btn-default" href="#" onclick="drop_confirm('确认设置为未中奖?','{php echo $this->createWebUrl('setstatus',array('status'=>2,'id'=>$row['id'],'rid'=>$row['rid']))}');"><i class="fa fa-times-circle-o"></i> 确认兑奖</a>{/if}
						{if $row['status']==2}<a class="btn btn-warning" href="#" onclick="drop_confirm('确认设置为已兑奖?','{php echo $this->createWebUrl('setstatus',array('status'=>1,'id'=>$row['id'],'rid'=>$row['rid']))}');"><i class="fa fa-check-circle-o"></i> 取消中奖</a>{/if}
					</td>
				</tr>
				{/loop}
				<tr>
					<td><input type="checkbox" name="" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});"></td>
					<td colspan="7"><input name="token" type="hidden" value="{$_W['token']}" /><input type="submit" name="submit" class="btn btn-primary" value="删除选中的中奖记录"></td>
				</tr>
			</tbody>
		</table>
	</div>
</div>
</form>
</div>
<div style="text-align:center;">{$pager}</div>
</div>
<div id="guanbi" class="hide">
	<span type="button" class="pull-right btn btn-primary" data-dismiss="modal" aria-hidden="true">关闭</span>
</div>
<script>
require(['jquery', 'util'], function($, u){
		$('#form1').submit(function(){
		    if($(":checkbox[name='uid[]']:checked").size() > 0){
			    var check = $(":checkbox[name='uid[]']:checked");
			    if( confirm("确认要删除选择的粉丝中奖记录?")){
		            var id = new Array();
				    var rid = {$rid};
		            check.each(function(i){
			            id[i] = $(this).val();
		            });
		            $.post('{php echo $this->createWebUrl('deleteaward')}', {idArr:id,rid:rid},function(data){
			        if (data.errno ==0){
						location.reload();
			        } else {
				        alert(data.error);
			        }
		            },'json');
		        }
		    }else{
		        u.message('没有选择粉丝', '', 'error');
		        return false;
		    }
	    });
		$('.userinfo').click(function(){
			var fid = parseInt($(this).attr('fid'));
			$.get("{php echo url('site/entry/userinfo',array('m' => 'stonefish_redenvelope','rid' => $rid))}&uid=" + fid, function(data){
				if(data == 'dataerr') {
					u.message('未找到指定粉丝资料', '', 'error');
				} else {
					var obj = u.dialog('粉丝资料兑奖参数', data, $('#guanbi').html());
				}
				obj.modal('show');
			});
		})
		
	});
	function drop_confirm(msg, url){
    if(confirm(msg)){
        window.location = url;
    }
}
</script>
{template 'common/footer'}